package servlet.admin;

import entity.Util;
import service.admin.ManagerDelService;
import service.admin.impl.ManagerDelServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * ManagerDelServlet
 *
 * @author ChenYanMei
 * @version 2023/9/5
 */
@WebServlet("/admin/managerDel")
public class ManagerDelServlet extends HttpServlet {
    ManagerDelService service = new ManagerDelServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/json; charset=utf8");
        String id = req.getParameter("id");
        int result = 0;

        // 返回参数
        int code = 1;
        String msg = "";
        PrintWriter out = resp.getWriter();

        result = service.del(Integer.valueOf(id));
        if (result == 1) {
            code = 0;
            msg = "删除成功";
        } else {
            msg = "删除失败";
        }

        out.print(Util.jsonResponse(code, msg, null));
    }
}
